Denotes a block. Blocks are typically used with functions, Else, Loop, and IF-commands.
{
zero or more commands
}
A block is used to bind two or more commands together. It can also be used to change which IF an ELSE belongs to, as in this example where the block forces the ELSE to belong to the first IF rather than the second:
if var1 = 1 { if var2 = abc sleep, 1 } else return
Although blocks can be used anywhere, currently they are only meaningful when used with functions, Else, Loop, or an IF-type command such as IfEqual or IfWinExist.
If an IF, ELSE, or Loop has only a single command, that command need not be enclosed in a block. However, there may be cases where doing so enhances the readability or maintainability of the script.
A block may be empty (contain zero commands), which may be useful in cases where you want to comment out the contents of the block without removing the block itself.
One True Brace (OTB, K&R style): In v1.0.41+, the OTB style may optionally be used in the following places: expression if-statements, the "else" keyword, normal loops, and function definitions. This style puts the block's opening brace on the same line as the block's controlling statement rather than underneath on a line by itself. For example:
if (x < y) { ... } else { ... } Loop %RepeatCount% { ... } MyFunction(x, y) { ... }
Similarly, a command or other action may exist on the same line as an open-brace (v1.0.41.01+). For example:
if x = 1 { MsgBox This line appears to the right of an open-brace. MsgBox This is the next line. }
However, open-braces of the One True Brace style do not support commands to their right.
Functions, Loop, Else, If, If(Expression)
if x = 1 { MsgBox, test1 Sleep, 5 } else MsgBox, test2